home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.12 Dec 96 / Custom AppMaker 2 / AM Code / CSoundsDemoDoc.cp < prev    next >
Encoding:
Text File  |  1996-03-20  |  4.9 KB  |  225 lines  |  [TEXT/CWIE]

  1. // CSoundsDemoDoc.cp -- Document methods
  2. // Created 20/3/96 12:28 by AppMaker
  3.  
  4. #include "CSoundsDemoDoc.h"
  5.  
  6. #include "CSoundsDemoData.h"
  7. #include "CMain.h"
  8. #include "CmdCodes.h"
  9.  
  10. #include <LFile.h>
  11. #include <LPlaceHolder.h>
  12. #include <LPrintout.h>
  13. #include <LWindow.h>
  14. #include <UWindows.h>
  15. #include <String_Utils.h>
  16.  
  17. const ResIDT    prto_PrintView        = 201;
  18. const ResIDT    STRx_Untitled        = 128;
  19.  
  20. // ---------------------------------------------------------------------------
  21. //        • CSoundsDemoDoc
  22. // ---------------------------------------------------------------------------
  23.  
  24. CSoundsDemoDoc::CSoundsDemoDoc(
  25.     LCommander    *inSuper)
  26.         : LSingleDoc(inSuper)
  27. {
  28.     mData = new CSoundsDemoData();
  29. }
  30.  
  31. // ---------------------------------------------------------------------------
  32. //        • ~CSoundsDemoDoc
  33. // ---------------------------------------------------------------------------
  34. //    Destructor
  35. //
  36.  
  37. CSoundsDemoDoc::~CSoundsDemoDoc()
  38. {
  39.     delete mData;
  40. }
  41.  
  42. //----------
  43. void
  44. CSoundsDemoDoc::newFile()
  45. {
  46.     mData->newData();
  47.  
  48.     MakeWindows();
  49.  
  50.     NameNewDoc();        // Set name of untitled window
  51. }
  52.  
  53. //----------
  54. void
  55. CSoundsDemoDoc::openFile(
  56.     FSSpec        *inFileSpec)
  57. {
  58.     mData->openData (inFileSpec);
  59.  
  60.     MakeWindows();
  61.  
  62.     if (mWindow != nil) {
  63.         mWindow->SetDescriptor (inFileSpec->name);
  64.     }
  65.     mIsSpecified = true;
  66. }
  67.  
  68. // ---------------------------------------------------------------------------
  69. //        • MakeWindows
  70. // ---------------------------------------------------------------------------
  71.  
  72. void
  73. CSoundsDemoDoc::MakeWindows()
  74. {
  75.     mMain = CMain::CreateMain(this, mData);
  76.  
  77.     mWindow = mMain;
  78. }
  79.  
  80. // ---------------------------------------------------------------------------
  81. //        • NameNewDoc
  82. // ---------------------------------------------------------------------------
  83. //    Name a new, untitled document window
  84. //
  85. //    Untitled windows start with "untitled", then "untitled 1",
  86. //    "untitled 2", etc. Old numbers are reused, so there won't be
  87. //    gaps in the numbering.
  88. //
  89. //    This routine uses a STR# resource to store the "untitled" string,
  90. //    which can be localized to different languages. The first string
  91. //    is "untitled" and the second is "untitled " (trailing space),
  92. //    which is used when appending a number to the name.
  93.  
  94. void
  95. CSoundsDemoDoc::NameNewDoc()
  96. {
  97.         // Start with the default name("untitled")
  98.     Str255    name;
  99.     ::GetIndString(name, STRx_Untitled, 1);
  100.  
  101.     long    num = 0;
  102.     while (UWindows::FindNamedWindow(name) != nil) {
  103.  
  104.             // An existing window has the current name
  105.             // Increment counter and try again
  106.  
  107.         ::GetIndString(name, STRx_Untitled, 2);
  108.         num++;
  109.         Str15    numStr;
  110.         ::NumToString(num, numStr);
  111.         ConcatPStr(name, numStr);
  112.     }
  113.  
  114.     mWindow->SetDescriptor(name);        // Finally, set window title
  115. }
  116.  
  117. // ---------------------------------------------------------------------------
  118. //        • IsModified
  119. // ---------------------------------------------------------------------------
  120. //    Return whether the Document has changed since the last save
  121.  
  122. Boolean
  123. CSoundsDemoDoc::IsModified()
  124. {
  125.     mIsModified = mData->IsDirty();
  126.  
  127.     return mIsModified;
  128. }
  129.  
  130. // ---------------------------------------------------------------------------
  131. //        • DoAESave
  132. // ---------------------------------------------------------------------------
  133. //    Save Document in the specified file with the specified file type
  134. //
  135. //    If file type is fileType_Default, use the normal file type for
  136. //    this document
  137.  
  138. void
  139. CSoundsDemoDoc::DoAESave(
  140.     FSSpec    &inFileSpec,
  141.     OSType    inFileType)
  142. {
  143.     mData->DoSaveAs(&inFileSpec);                // Write out data
  144.                                         // Change window name
  145.     mWindow->SetDescriptor(inFileSpec.name);
  146. }
  147.  
  148. //----------
  149. void
  150. CSoundsDemoDoc::DoSave()
  151. {
  152.     mData->DoSave();
  153. }
  154.  
  155. //----------
  156. void
  157. CSoundsDemoDoc::DoRevert()
  158. {
  159.     mData->DoRevert();
  160. }
  161.  
  162. // ---------------------------------------------------------------------------
  163. //        • DoPrint
  164. // ---------------------------------------------------------------------------
  165. //    Print the contents of the Document
  166.  
  167. void
  168. CSoundsDemoDoc::DoPrint()
  169. {
  170.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  171.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  172.                                     thePrintout->FindPaneByID('TBox');
  173. //!    textPlace->InstallOccupant(mTextView, atNone);
  174.  
  175.  
  176.     thePrintout->DoPrintJob();
  177.     delete thePrintout;
  178. }
  179.  
  180. //----------
  181. Boolean
  182. CSoundsDemoDoc::ObeyCommand(
  183.     CommandT    inCommand,
  184.     void        *ioParam)
  185. {
  186.     Boolean        cmdHandled = true;
  187.  
  188.     switch (inCommand) {
  189.  
  190.     // +++ Add cases here for the commands you handle
  191.     //        Remember to add same cases to FindCommandStatus below
  192.     //        to enable/disable the menu items for the commands
  193.  
  194.  
  195.     default:
  196.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  197.         break;
  198.     }
  199.  
  200.     return cmdHandled;
  201. }
  202.  
  203. //----------
  204. void
  205. CSoundsDemoDoc::FindCommandStatus(
  206.     CommandT    inCommand,
  207.     Boolean        &outEnabled,
  208.     Boolean        &outUsesMark,
  209.     Char16        &outMark,
  210.     Str255        outName)
  211. {
  212.     outUsesMark = false;
  213.  
  214.     switch (inCommand) {
  215.  
  216.     // +++ Add cases here for the commands you handle
  217.  
  218.  
  219.     default:
  220.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  221.                                             outUsesMark, outMark, outName);
  222.         break;
  223.     }
  224. }
  225.